package com.source.diyjuc;

import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @Author wengqy
 * @Date 2021/1/18
 */
public class ABADemo2 {

    static  volatile    AtomicStampedReference<Integer> atomicStampedReference   = new AtomicStampedReference(100,1);

    public static void main(String[] args) {
       // compareAndSet(V   expectedReference, V   newReference,int expectedStamp, int newStamp)
        System.out.println("A  "+atomicStampedReference.getStamp() +"    "+atomicStampedReference.getReference());   //1

        boolean x = atomicStampedReference.compareAndSet(100, 200, atomicStampedReference.getStamp(), atomicStampedReference.getStamp()+1);
        System.out.println(x);
        System.out.println("B  "+atomicStampedReference.getStamp()+"    "+atomicStampedReference.getReference());  // 2
        System.out.println(atomicStampedReference.getReference());


        boolean b = atomicStampedReference.compareAndSet(200, 180, 2, 3);
        System.out.println("--"+b);


      //  System.out.println("C  "+atomicStampedReference.getStamp()); //2
     //   System.out.println(atomicStampedReference.compareAndSet(100, 500, atomicStampedReference.getStamp(), atomicStampedReference.getStamp() + 1));

        Integer reference = atomicStampedReference.getReference();
       // System.out.println(reference);



    }
}
